<!DOCTYPE html>
<html class="Content">
<head>
    <title>xUnit.js: Data-Driven Tests</title>
    <link type="text/css" rel="Stylesheet" href="../../Style/documentation.css" />
</head>
<body>
    <h1>Data-Driven Tests</h1>
    <p>
        Tests can be parameterized and executed multiple times with different sets of data, by setting <em>Fact</em><strong>.Data</strong> to an array of values.
    </p>
    <p>
        Each value will be passed into the fact method as an argument, e.g.: 
        <span class="Code">
function FactoryStrategiesReturnCorrectTargets(<strong>data</strong>){
    // Arrange
    var expected=<strong>data</strong>.value;
    var target=new <strong>data</strong>.targetClass();

    // Act
    var actual=target.create();
        
    // Assert
    Assert.Equal(expected, actual);
}
        </span>
    </p>
    <p>
        If a test with data is marked asynchronous, the asynchronous callback will be passed in as the first argument, and the data argument will be passed in second:
        <span class="Code">
function SetsPageTitle(callback,<strong>data</strong>){
    // Arrange
    var expected=<strong>data</strong>.title;
    var target=<strong>data</strong>.url;

    // Act
    page.load(target, function(pageObject){
        callback(function(){
            var actual=pageObject.title;
        
            // Assert
            Assert.Equal(expected, actual);
        });
    })
}
        </span>
    </p>
</body>
</html>